﻿using System;
using System.ComponentModel.Composition;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using ASPItalia.ModelVirtualCasting.Parts;
using System.Data.Entity;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
	[Export("CountryRepository", typeof(ICountryRepository))]
	[PartCreationPolicy(CreationPolicy.NonShared)]
	[RepositoryMetadata(Name = "CountryRepository", IsFake = false)]
	public class CountryRepository : BaseRepository<Country>, ICountryRepository
	{
		[ImportingConstructor()]
		public CountryRepository(IContextContainer container)
			: base(container)
		{
		}

		public IQueryable<Country> GetAll()
		{
			return CurrentSet;
		}

		public IQueryable<Country> Where(Expression<Func<Country, bool>> predicate)
		{
			return CurrentSet.Where(predicate);
		}

		public long Count(System.Linq.Expressions.Expression<Func<Country, bool>> predicate)
		{
			return CurrentSet.Count(predicate);
		}

		public Country GetByID(int id)
		{
			return CurrentSet.Where(c => c.CountryID == id).Single();
		}

		public ICountryRepository Include<TProperty>(Expression<Func<Country, TProperty>> path)
		{
			IncludeInternal(path);
			return this;
		}

		public ICountryRepository Include(string path)
		{
			IncludeInternal(path);
			return this;
		}

		public ICountryRepository CreateQuery()
		{
			CreateQueryInternal();
			return this;
		}

		public ICountryRepository EnableLazyLoading()
		{
			SetLazyLoading(true);
			return this;
		}

		public ICountryRepository DisableLazyLoading()
		{
			SetLazyLoading(false);
			return this;
		}

		public ICountryRepository DoNotTrack()
		{
			base.DoNotTrackInternal();
			return this;
		}
	}
}